package cn.htsyb.synergy.utils;

import java.util.Random;
/**
 * 
 * @author lakeside hubin_yuan.410@hotmail.com
 * @version V1.0.0
 * @since 1.0
 * @date 2022/5/11
 */
public class RandomUtil {
    public static final char[] CHARACTERISTIC = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'G', 'K', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c',
            'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '2', '3', '4', '5', '6', '7', '8', '9'};
    static Random random = new Random();

    /**
     * 随机一个数字
     *
     * @param max
     * @return
     */
    public static int randomNumber(int max) {
        return random.nextInt(max);
    }

    /**
     * 区间随机数
     *
     * @param max 最大阀值
     * @param min 最小阀值
     * @return 随机数值
     */
    public static int randomSection(int min, int max) {
        return random.nextInt(max) % (max - min + 1) + min;
    }

    /**
     * 从指定字符集中随机无序取指定长度的字符
     *
     * @param characteristic 特征字符集
     * @param length         指定长度
     * @return 随机字符集
     */
    public static char[] randomChar(char[] characteristic, int length) {
        char[] randomChar = new char[length];
        for (int i = 0; i < length; i++) {
            randomChar[i] = characteristic[randomSection(0, characteristic.length)];
        }
        return randomChar;
    }

    /**
     * 随机构建序列号<br>
     *
     * @param length
     * @return 随机序列号字符串
     */
    public static String randomSequence(int length) {
        return String.valueOf(randomChar(CHARACTERISTIC, length));
    }

}
